﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using APH.Parl2.Shared.Contracts;
using System.ServiceModel;
using System.IO;

namespace APH.Parl2.Business.Publishing
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, UseSynchronizationContext = false, IncludeExceptionDetailInFaults = true)]
    public class PublishingManager : IPublishingManager
    {
        [OperationBehavior(TransactionScopeRequired = true)]
        public void Publish(IncomingDocumentData documentData)
        {
            ITranslationEngine translationEngine = new TranslationEngine();
            var translatedDocumentData = translationEngine.TranslateDocument(documentData);

            IValidationEngine validationEngine = new ValidationEngine();
            validationEngine.Validate(translatedDocumentData);

            IPublishingEngine publishingEngine = new PublishingEngine();
            Guid documentId = publishingEngine.PublishDocument(translatedDocumentData);

            IPublishEvents publishEvents = new PublishEventsClient("PublishEvent.MSMQ");
            publishEvents.OnPublished(documentId);
        }
    }
}
